﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Windows.Input;
using System.ComponentModel;
using System.Linq;
using MachineQA.DataAccess;
using MachineQA.Properties;
using MachineQA.Model;

namespace MachineQA.ViewModel
{
    class EnergiesViewModel : WorkspaceViewModel
    {
        readonly EnergyRepository _energyRepository;
        ObservableCollection<EnergyViewModel> _allEnergies;

        public EnergiesViewModel(EnergyRepository energyRepository)
        {
            _energyRepository = energyRepository;
            if(_energyRepository.GetEnergies().Count() == 0)
            {
                Modality newModality = new Modality();
                newModality.Name = "photon";
                newModality.Unit = "MV";
                Energy newEnergy = new Energy();
                newEnergy.Modality = newModality;
                newEnergy.value = 6;
                _energyRepository.AddEnergy(newEnergy);
            }
            this.CreateAllEnergies();
        }   

        void CreateAllEnergies()
        {
            List<EnergyViewModel> all = (from energy in _energyRepository.GetEnergies()
                                         select new EnergyViewModel(energy, _energyRepository)).ToList();

            _allEnergies = new ObservableCollection<EnergyViewModel>(all);
        }

        public ObservableCollection<EnergyViewModel> AllEnergies
        {
            get
            {
                return _allEnergies;
            }
        }
    }
}
